package com.wc.alorithm_blue_bridge._数学知识.推导.小蓝与钥匙;

/**
 * @Author congge
 * @Date 2025/3/17 21:12
 * @description
 * https://www.lanqiao.cn/courses/46292/learning/?id=3949616&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 首先14 个人拿到的是自己的钥匙 C(28, 14)
     * 剩下14 个人都不是自己的钥匙 那就是全错排
     */
    static int N = 29;
    static long[][] f = new long[N][N];
    static long[] g = new long[N];
    static int n = 14;

    public static void main(String[] args) {
        g[2] = 1;
        for (int i = 3; i <= n; i++) g[i] = (i - 1) * (g[i - 1] + g[i - 2]);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= Math.min(n, i); j++) {
                if (j == 0) f[i][j] = 1;
                else f[i][j] = (f[i - 1][j] + f[i - 1][j - 1]);
            }
        }
        System.out.println(f[28][14] * g[14]);
    }
}
